﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OConf.Common;
using OConf.IBLL;
using OConf.Model;
using OConf.Model.Common;

namespace OConf.API.Controllers
{
    /// <summary>
    /// 管理员操作
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AdminLoginController : ControllerBase
    {
        private readonly IAdminBLL _adminBLL;
        public AdminLoginController(IAdminBLL adminBLL)
        {
            _adminBLL = adminBLL;
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public ReturnData<UserLoginResponse> UserLogin([FromBody] UserLoginInput input)
        {
            return _adminBLL.UserLogin(input.UserName, input.Password);
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ReturnData<UserInfoResponse> UserInfo()
        {
            UserInfoResponse userInfoResponse = new UserInfoResponse();
            userInfoResponse.Username = ManagerUnit.GetCurrentName();
            return ReturnDataHelper<UserInfoResponse>.Success("操作成功", userInfoResponse);
        }

        /// <summary>
        /// 账号退出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object Logout()
        {
            return new { Code = 200, Msg = "Success" };
        }
    }
}
